package com.hwadee.controller;


import com.hwadee.pojo.ElderUser;
import com.hwadee.service.ElderUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/api/elderuser")
public class ElderUserController {

    @Autowired
    private ElderUserService elderUserService;

    //查询老年用户列表接口，可根据用户名或手机号进行模糊搜索
    @GetMapping("/list")
    public List<ElderUser> list(
            @RequestParam(required = false) String username,
            @RequestParam(required = false) String phone
    ){
        return elderUserService.searchUsers(username, phone);
    }
    //更新老年用户信息接口
    @PutMapping("/update")
    public String updateUser(@RequestBody ElderUser user) {
        elderUserService.updateUser(user);
        return "success";
    }
    //删除指定 ID 的老年用户接口
    @DeleteMapping("/delete/{id}")
    public String deleteUser(@PathVariable Integer id) {
        elderUserService.deleteUserById(id);
        return "success";
    }
}
